package org.example.service;

import org.example.entity.FreeTicket;
import org.example.entity.Movie;
import org.example.entity.StudentTicket;
import org.example.entity.Ticket;

import java.util.Map;

import static org.example.service.ICinemaService.MOVIE_MAP;

public class BuyTicketService implements IBuyTicketService{
    private static java.util.Scanner in = new java.util.Scanner(System.in);
    CinemaService cinemaService = new CinemaService();

    @Override
    public Ticket buyTicket(String name, String playTime, int type) {
        Movie movie = cinemaService.getMovieByName(name, playTime);
        if (movie != null) {
            Ticket ticket = null;
            switch (type) {
                case 1:
                    ticket = new Ticket(movie);
                    break;
                case 2:
                    ticket = new StudentTicket(movie);
                    break;
                case 3:
                    System.out.println("请输入客户名称");
                    String customerName = in.next();
                    ticket = new FreeTicket(movie, customerName);
                    break;
                default:
                    System.out.println("请选择正确的类型");
                    return null;
            }
            if (ticket instanceof StudentTicket){
                StudentTicket studentTicket = (StudentTicket) ticket;
//                studentTicket.setMovie( movie);
                studentTicket.setDiscount(8);
                studentTicket.printTicket();
                TicketService.saveTicket(studentTicket);
            } else if (ticket instanceof FreeTicket) {
                FreeTicket freeTicket = (FreeTicket) ticket;
//                freeTicket.setMovie( movie);
                freeTicket.printTicket();
                TicketService.saveTicket(freeTicket);
            }else  {
//                ticket.setMovie( movie);
                ticket.printTicket();
                TicketService.saveTicket(ticket);
            }
        }
        return null;
    }


}
